package liumengbaio.lolzhangyoubao.Activity.Adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import liumengbaio.lolzhangyoubao.Activity.InFo.HeroManitoInfo;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/9/5.
 */
public class HeroManitoAdapter extends BaseAdapter {
    private List<HeroManitoInfo.DataBean> heroManitoInfos;
    private Context context;

    public HeroManitoAdapter(List<HeroManitoInfo.DataBean> heroManitoInfos, Context context) {
        this.heroManitoInfos = heroManitoInfos;
        this.context = context;
    }

    @Override
    public int getCount() {
        return heroManitoInfos.size();
    }

    @Override
    public Object getItem(int position) {
        return heroManitoInfos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHold viewHold = null;
        if (viewHold == null) {
            viewHold = new ViewHold();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_herodata, null);
            viewHold.iv_icon= (ImageView) convertView.findViewById(R.id.iv_icon);
            viewHold.tv_rank= (TextView) convertView.findViewById(R.id.tv_rank);
            viewHold.tv_name= (TextView) convertView.findViewById(R.id.tv_name);
            viewHold.tv_skill_exp= (TextView) convertView.findViewById(R.id.tv_skill_exp);
            convertView.setTag(viewHold);
        } else {
            viewHold = (ViewHold) convertView.getTag();

        }
        HeroManitoInfo.DataBean bean = heroManitoInfos.get(position);
        if (bean.getRank()>3){
            viewHold.tv_rank.setTextColor(Color.WHITE);
        }
        viewHold.tv_rank.setText(bean.getRank()+"");
        Picasso.with(context).load(bean.getAvatar_url()).into(viewHold.iv_icon);
        viewHold.tv_name.setText(bean.getUsername()+"-"+bean.getArea_name());
        viewHold.tv_skill_exp.setText(bean.getProficiency()+"");

        return convertView;


    }

    private class ViewHold {
        private ImageView iv_icon ;
        private TextView tv_rank,tv_name,tv_skill_exp;
    }
}
